ViewPropertyAnimator

ViewPropertyAnimator 使用

需要手动 cancel 动画

mContentContainer.animate()
    .setDuration(5000L)
    .translationX(mContentContainer.width.toFloat())
    .setListener(object : AnimatorListenerAdapter() {
        override fun onAnimationStart(animation: Animator) {
            super.onAnimationStart(animation)
            Logger.i(TAG, "onAnimationStart:$animation")
        }
    
        override fun onAnimationEnd(animation: Animator) {
            super.onAnimationEnd(animation)
            Logger.d(
                TAG,
                "collapse onAnimationEnd, mContentContainer gone, mHandleContainer visible mContentContainer.isAttachedToWindow=${mContentContainer.isAttachedToWindow}, mContentContainer.width=${mContentContainer.width}."
            )
            mContentContainer.gone()
            mHandleContainer.visible()
        }
    })
    .start()

ViewPropertyAnimatorCompat 是用一个 WeakHashMap 将 View 存起来的,可以不用 cancel 动画

ViewCompat.animate(mContentContainer)
    .setDuration(5_000L)
    .translationX(mContentContainer.width.toFloat())
    .setListener(object : ViewPropertyAnimatorListener {
        override fun onAnimationStart(view: View) {
        }

        override fun onAnimationEnd(view: View) {
            Logger.d(
                TAG,
                "collapse onAnimationEnd, mContentContainer gone, mHandleContainer visible mContentContainer.isAttachedToWindow=${mContentContainer.isAttachedToWindow}, mContentContainer.width=${mContentContainer.width}."
            )
            mContentContainer.gone()
            mHandleContainer.visible()
        }

        override fun onAnimationCancel(view: View) {
            Logger.w(
                TAG,
                "collapse onAnimationCancel"
            )
        }
    })
    .start()